import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
import { TimeEntity } from '@/pmp/entity/base/time.entity';
import { PmpSysRoleEntity } from '@/pmp/entity/pmp.sys.role.entity';

@Entity('pmp-sys-sub-role')
export class PmpSysSubRoleEntity extends TimeEntity {
  @PrimaryGeneratedColumn()
  id: bigint;

  @Column()
  role_name: string;

  @Column()
  role_key: string;

  @Column()
  description: string;

  @Column({
    type: 'bigint', // 显式声明 MySQL 支持的类型
    unsigned: true, // 如果需要使用无符号的 BigInt，则设置为 `true`
  })
  parent_id: number;

  @ManyToOne(() => PmpSysRoleEntity, (parentRole) => parentRole['children'], {
    nullable: false,
    onDelete: 'CASCADE', // 父角色删除后，关联的子角色也会被删除
  })
  'pmp-sys-role': PmpSysRoleEntity;
}
